## [1] "Run Completed at 2018-02-05 19:51:06"

Absence data

Models

Random Baseline

\[ Yobs_{i,j} \sim Bernoulli(N(0,1.68)) \]

Note that this is a random probability of interaction on a per observation basis. This is different than a random link model. If we are interested in a binary network, a random interaction probability model will lead to a link probability of 1-(1/2)^n in n sampling events.

## sink("models/SpeciesIdentity.jags")
## cat("
##     model {
##     
##     for (x in 1:Nobs){
## 
##     #observation
##     logit(s[x])<-alpha[Bird[x],Plant[x]]
##     Yobs[x] ~ dbern(s[x])
##     
##     #Observed discrepancy
##     E[x]<-abs(Yobs[x]- s[x])
##     }
##     
##     #Assess Model Fit - Predict remaining data
##     for(x in 1:Nnewdata){
##     
##       #Generate prediction
##       logit(snew[x])<-alpha[NewBird[x],NewPlant[x]]
##       Ynew_pred[x]~dbern(snew[x])
##     
##       #Assess fit, proportion of corrected predicted observations
##       Enew[x]<-abs(Ynew[x]-Ynew_pred[x])
## 
##     }
##     
##     #Priors
## 
##     #Species level priors
##     for (i in 1:Birds){
##       for (j in 1:Plants){
## 
##         #Intercept
##         #logit prior, then transform for plotting
##         alpha[i,j] ~ dnorm(0,0.386)
##       } 
##     }
## 
##     #derived posterior check
##     fit<-sum(E[]) #Discrepancy for the observed data
##     fitnew<-sum(Enew[])
##     }
##     ",fill=TRUE)
## 
## sink()
## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
## Graph information:
##    Observed stochastic nodes: 0
##    Unobserved stochastic nodes: 51464
##    Total graph size: 278660
## 
## Initializing model

Assess Convergence

Species Identity

\[ Yobs_{i,j} \sim Bernoulli(\lambda_{i,j}) \]

## sink("models/SpeciesIdentity.jags")
## cat("
##     model {
##     
##     for (x in 1:Nobs){
## 
##     #observation
##     logit(s[x])<-alpha[Bird[x],Plant[x]]
##     Yobs[x] ~ dbern(s[x])
##     
##     #Observed discrepancy
##     E[x]<-abs(Yobs[x]- s[x])
##     }
##     
##     #Assess Model Fit - Predict remaining data
##     for(x in 1:Nnewdata){
##     
##       #Generate prediction
##       logit(snew[x])<-alpha[NewBird[x],NewPlant[x]]
##       Ynew_pred[x]~dbern(snew[x])
##     
##       #Assess fit, proportion of corrected predicted observations
##       Enew[x]<-abs(Ynew[x]-Ynew_pred[x])
## 
##     }
##     
##     #Priors
## 
##     #Species level priors
##     for (i in 1:Birds){
##       for (j in 1:Plants){
## 
##         #Intercept
##         #logit prior, then transform for plotting
##         alpha[i,j] ~ dnorm(0,0.386)
##       } 
##     }
## 
##     #derived posterior check
##     fit<-sum(E[]) #Discrepancy for the observed data
##     fitnew<-sum(Enew[])
##     }
##     ",fill=TRUE)
## 
## sink()
## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
## Graph information:
##    Observed stochastic nodes: 21334
##    Unobserved stochastic nodes: 30130
##    Total graph size: 238052
## 
## Initializing model

Assess Convergence

Trait-matching

For hummingbird species i feeding on plant species j observed at time k and sampling event observed by transect

Process Model:

\[ N_{i,j,k} \sim Binomial(\lambda_{i,j,k}) \] \[ logit(\lambda_{i,j,k}) = \alpha_i + \beta_{1,i} * Traitmatch_{i,j} \]

## sink("models/TraitMatch.jags")
## cat("
##     model {
##     
##     for (x in 1:Nobs){
##   
##     logit(s[x])<-alpha[Bird[x]] + beta1[Bird[x]] * Traitmatch[Bird[x],Plant[x]] 
##     Yobs[x] ~ dbern(s[x])
##     
##     #Observed discrepancy
##     E[x]<-abs(Yobs[x]- s[x])
##     }
##     
##     #Assess Model Fit - Predict remaining data
##     for(x in 1:Nnewdata){
##     
##     #Generate prediction
##     logit(snew[x])<-alpha[NewBird[x]] + beta1[NewBird[x]] * Traitmatch[NewBird[x],NewPlant[x]] 
##     Ynew_pred[x]~dbern(snew[x])
##     
##     #Assess fit, proportion of corrected predicted links
##     Enew[x]<-abs(Ynew[x]-Ynew_pred[x])
##     
##     }
##     
##     #Priors
## 
##     #Process Model
##     #Species level priors
##     for (i in 1:Birds){
##     
##     #Intercept
##     #logit prior, then transform for plotting
##     alpha[i] ~ dnorm(alpha_mu,alpha_tau)
##     
##     #Traits slope 
##     beta1[i] ~ dnorm(beta1_mu,beta1_tau)    
##     
##     }
##     
##     #Group process priors
##     
##     #Intercept 
##     alpha_mu ~ dnorm(0,0.386)
##     alpha_tau ~ dt(0,1,1)I(0,)
##     alpha_sigma<-pow(1/alpha_tau,0.5) 
##     
##     #Trait
##     beta1_mu~dnorm(0,0.386)
##     beta1_tau ~ dt(0,1,1)I(0,)
##     beta1_sigma<-pow(1/beta1_tau,0.5)
##     
##     #derived posterior check
##     fit<-sum(E[]) #Discrepancy for the observed data
##     fitnew<-sum(Enew[])
##     
##     }
##     ",fill=TRUE)
## 
## sink()
## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
## Graph information:
##    Observed stochastic nodes: 21334
##    Unobserved stochastic nodes: 28286
##    Total graph size: 238845
## 
## Initializing model

Assess Convergence

Detectability

To Do. Should I also do traits without the detection probabilities?

Species Identity

Observation Model:

\[ Yobs_{i,j,k,d} \sim Binomial(N_{i,j,k},\omega_i) \]

Process Model:

\[ N_{i,j,k} \sim Binomial(\lambda_{i,j}) \] \[ Yobs_{i,j} \sim Bernoulli(\lambda_{i,j}) \]

## sink("models/SpeciesIdentity_Detect.jags")
## cat("
##     model {
##     
##     #Observation Model
##     for (x in 1:Nobs){
##       
##       #Observation Process
##       #True state
##       z[x] ~ dbern(detect[Bird[x]]) 
##       
##       #Observation
##       logit(s[x])<-alpha[Bird[x],Plant[x]]
##       p[x]<-z[x] * s[x]
##       Yobs[x] ~ dbern(p[x])
##       
##       #Observed discrepancy
##       E[x]<-abs(Yobs[x]- s[x])
##     }
##     
##     #Assess Model Fit - Predict remaining data
##     for(x in 1:Nnewdata){
##     
##       #Generate prediction
##       znew[x] ~ dbern(detect[NewBird[x]])
##       logit(snew[x])<-alpha[NewBird[x],NewPlant[x]]
##       pnew[x]<-znew[x]*snew[x]
##   
##       #Predicted observation
##       Ynew_pred[x]~dbern(pnew[x])
##       
##       #Assess fit, proportion of corrected predicted links
##       Enew[x]<-abs(Ynew[x]-Ynew_pred[x])
##     
##     }
##     
##     #Priors
##     #Observation model
##     #Detect priors, logit transformed - Following lunn 2012 p85
##     for(x in 1:Birds){
##       logit(detect[x])<-dcam[x]
##       dcam[x]~dnorm(omega_mu,omega_tau)
##     }
##     
##     #Process Model
##     #Species level priors
##     for (i in 1:Birds){
##       for (j in 1:Plants){
##         #Intercept
##         #logit prior, then transform for plotting
##         alpha[i,j] ~ dnorm(0,0.386)
##       } 
##     }
##     
##     #OBSERVATION PRIOR
##     omega_mu ~ dnorm(0,0.386)
##     omega_tau ~ dunif(0,10)
##     
##     #derived posterior check
##     fit<-sum(E[]) #Discrepancy for the observed data
##     fitnew<-sum(Enew[])
##     
##     }
##     ",fill=TRUE)
## 
## sink()
## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
## Graph information:
##    Observed stochastic nodes: 21334
##    Unobserved stochastic nodes: 79704
##    Total graph size: 337199
## 
## Initializing model

Assess Convergence

Trait-matching

For hummingbird species i feeding on plant species j observed at time k and sampling event observed by transect

Observation Model:

\[ Yobs_{i,j,k,d} \sim Binomial(N_{i,j,k},\omega_i) \]

Process Model:

\[ N_{i,j,k} \sim Binomial(\lambda_{i,j,k}) \] \[ logit(\lambda_{i,j,k}) = \alpha_i + \beta_{1,i} * Traitmatch_{i,j} \]

## sink("models/TraitMatch_Detect.jags")
## cat("
##     model {
##     
##     #Observation Model
##     for (x in 1:Nobs){
##     
##     #Observation Process
##     #True state
##     z[x] ~ dbern(detect[Bird[x]]) 
##     
##     #observation
##     logit(s[x])<-alpha[Bird[x]] + beta1[Bird[x]] * Traitmatch[Bird[x],Plant[x]] 
##     p[x]<-z[x] * s[x]
##     Yobs[x] ~ dbern(p[x])
##     
##     #Observed discrepancy
##     E[x]<-abs(Yobs[x]- s[x])
##     }
##     
##     #Assess Model Fit - Predict remaining data
##     for(x in 1:Nnewdata){
##     
##     #Generate prediction
##     znew[x] ~ dbern(detect[NewBird[x]])
##     logit(snew[x])<-alpha[NewBird[x]] + beta1[NewBird[x]] * Traitmatch[NewBird[x],NewPlant[x]] 
##     pnew[x]<-znew[x]*snew[x]
##     Ynew_pred[x]~dbern(pnew[x])
##     
##     #Assess fit, proportion of corrected predicted links
##     Enew[x]<-abs(Ynew[x]-Ynew_pred[x])
##     
##     }
##     
##     #Priors
##     #Observation model
##     #Detect priors, logit transformed - Following lunn 2012 p85
##     
##     for(x in 1:Birds){
##     logit(detect[x])<-dcam[x]
##     dcam[x]~dnorm(omega_mu,omega_tau)
##     }
##     
##     #Process Model
##     #Species level priors
##     for (i in 1:Birds){
##     
##     #Intercept
##     #logit prior, then transform for plotting
##     alpha[i] ~ dnorm(alpha_mu,alpha_tau)
##     
##     #Traits slope 
##     beta1[i] ~ dnorm(beta1_mu,beta1_tau)    
##     
##     }
##     
##     #OBSERVATION PRIOR
##     omega_mu ~ dnorm(0,0.386)
##     omega_tau ~ dunif(0,10)
##     
##     #Group process priors
##     
##     #Intercept 
##     alpha_mu ~ dnorm(0,0.386)
##     alpha_tau ~ dt(0,1,1)I(0,)
##     alpha_sigma<-pow(1/alpha_tau,0.5) 
##     
##     #Trait
##     beta1_mu~dnorm(0,0.386)
##     beta1_tau ~ dt(0,1,1)I(0,)
##     beta1_sigma<-pow(1/beta1_tau,0.5)
##     
##     #derived posterior check
##     fit<-sum(E[]) #Discrepancy for the observed data
##     fitnew<-sum(Enew[])
##     
##     }
##     ",fill=TRUE)
## 
## sink()
## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
## Graph information:
##    Observed stochastic nodes: 21334
##    Unobserved stochastic nodes: 77860
##    Total graph size: 337992
## 
## Initializing model

Assess Convergence

Abundance

Using the counts from the transects. Abundance is especially important to model, since its fluctuating all the time.

Do we have time for this?

Incorportating species occurrence

If species co-occurrence is a prerequisite for interaction, then the absence of interactions may stem either from a lack of detectability or species absence. We can jointly model the presence of species as a function of elevation and then existance of an interaction.

Species Identity

Observation Model:

\[ Yobs_{i,j,k,d} \sim Binomial(N_{i,j,k},\omega_i) \]

Process Model:

\[ N_{i,j,k} \sim Binomial(\lambda_{i,j}) \] \[ Yobs_{i,j} \sim Bernoulli(\lambda_{i,j}) \]

## sink("models/SpeciesIdentity_Detect_Elevation.jags")
## cat("
##     model {
##     
##     #Observation Model
##     for (x in 1:Nobs){
##     
##       #Occurrence Process
##       logit(psi[x])<-alpha_occ[Bird[x]] + beta_occ[Bird[x]] * elevation[x] + beta2_occ[Bird[x]] * elevation[x]^2
##       occ[x] ~ dbern(psi[x])
##       
##       #Is the species available to be detected?
##       rho[x]<-detect[Bird[x]]*occ[x]
##       
##       #Observation Process
##       #True state
##       z[x] ~ dbern(rho[x]) 
##       
##       #observation
##       logit(s[x])<-alpha[Bird[x],Plant[x]]
##       p[x]<-z[x] * s[x]
##       Yobs[x] ~ dbern(p[x])
##       
##       #Observed discrepancy
##       E[x]<-abs(Yobs[x]- s[x])
##     }
##     
##     #Assess Model Fit - Predict remaining data
##     for(x in 1:Nnewdata){
##     
##       #Generate prediction
##       #Occurrence Process
##       logit(psi_new[x])<-alpha_occ[NewBird[x]] + beta_occ[NewBird[x]] * elevation_new[x]
##       occ_new[x] ~ dbern(psi_new[x])
##       
##       #Is the species present to be detected?
##       rho_new[x]<-detect[NewBird[x]]*occ_new[x]
##       znew[x] ~ dbern(rho_new[x])
## 
##       logit(snew[x])<-alpha[NewBird[x],NewPlant[x]]
##       pnew[x]<-znew[x]*snew[x]
##   
##       #Predicted observation
##       Ynew_pred[x]~dbern(pnew[x])
##       
##       #Assess fit, proportion of corrected predicted links
##       Enew[x]<-abs(Ynew[x]-Ynew_pred[x])
##     
##     }
##     
##     #Priors
##     #Note: flat logit priorsm - Following lunn 2012 p85
## 
## 
##     #Occurrence Priors
##     for(x in 1:Birds){
##       alpha_occ[x] ~ dnorm(0,0.386)
##       beta_occ[x] ~ dnorm(0,0.386)
##       beta2_occ[x] ~ dnorm(0,0.386)
##     }
## 
##     #Observation model
## 
##     for(x in 1:Birds){
##       logit(detect[x])<-dcam[x]
##       dcam[x]~dnorm(omega_mu,omega_tau)
##     }
## 
##     
##     #Process Model
##     #Species level priors
##     for (i in 1:Birds){
##       for (j in 1:Plants){
##         #Intercept
##         #logit prior, then transform for plotting
##         alpha[i,j] ~ dnorm(0,0.386)
##       } 
##     }
##     
##     #OBSERVATION PRIOR
##     omega_mu ~ dnorm(0,0.386)
##     omega_tau ~ dunif(0,10)
##     
##     #derived posterior check
##     fit<-sum(E[]) #Discrepancy for the observed data
##     fitnew<-sum(Enew[])
##     
##     }
##     ",fill=TRUE)
## 
## sink()
## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
## Graph information:
##    Observed stochastic nodes: 21334
##    Unobserved stochastic nodes: 129364
##    Total graph size: 508394
## 
## Initializing model

Assess Convergence

Elevation ranges

Model Comparison

Predicted network statistics

Dashed line is the observed network from the time-series.

## # A tibble: 12 x 3
## # Groups:   L1 [?]
##    L1                       value     n
##    <chr>                    <dbl> <dbl>
##  1 Random                    0     22.3
##  2 Random                    1.00 838  
##  3 Species                   0    163  
##  4 Species                   1.00 697  
##  5 Species_Detect            0    443  
##  6 Species_Detect            1.00 417  
##  7 Species_Detect_Elevation  0    548  
##  8 Species_Detect_Elevation  1.00 312  
##  9 Traits                    0    446  
## 10 Traits                    1.00 414  
## 11 Traits_Detect             0    443  
## 12 Traits_Detect             1.00 417

Predicted betadiversity

Dissimilairty in interactions (Beta_WN from Poisot 2012) Dashed line is the observed network from the time-series.

Model overlap

Create a kind of venn diagram on PCA of model similarity based on per link discrepency.

## # A tibble: 24 x 3
## # Groups:   Model [6]
##    Model                      mean pair                                   
##    <chr>                     <dbl> <chr>                                  
##  1 Species_Detect_Elevation -1.00  Violet-tailed Sylph_Begonia longirostr…
##  2 Traits                   -0.960 Tawny-bellied Hermit_Centropogon presl…
##  3 Traits_Detect            -0.955 Booted Racket-tail_Stromanthe stromant…
##  4 Species_Detect           -0.950 Booted Racket-tail_Stromanthe stromant…
##  5 Species_Detect_Elevation -0.945 Tawny-bellied Hermit_Centropogon presl…
##  6 Traits_Detect            -0.945 Stripe-throated Hermit_Salvia quitensis
##  7 Species_Detect_Elevation -0.940 Booted Racket-tail_Stromanthe stromant…
##  8 Species_Detect_Elevation -0.938 Brown Inca_Psammisia aberrans          
##  9 Traits_Detect            -0.935 Tawny-bellied Hermit_Centropogon presl…
## 10 Traits                   -0.932 Brown Inca_Psammisia aberrans          
## # ... with 14 more rows

Without random model